// pages/nursingConsultation/index.js
import {
  ApiGetDepartMent,
  ApiGetDoctorList
} from '../../api/index'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    $path: app.globalData.$path,
    option1: [],
    option2: [{
        text: '全部护士',
        value: '全部护士'
      },
      {
        text: '护士',
        value: '护士'
      },
      {
        text: '护师',
        value: '护师'
      },
      {
        text: '主管护师',
        value: '主管护师'
      },
      {
        text: '副主任护师',
        value: '副主任护师'
      },
      {
        text: '主任护师',
        value: '主任护师'
      }
    ],
    value1: 0,
    value2: '全部护士',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)
    wx.setStorageSync('order_type', options.text)
    this.getDepartMent()
    this.getDoctorList()
  },
  //获取科室列表
  getDepartMent() {
    ApiGetDepartMent({
      sub_department: '1'
    }).then(res => {
      res.data.department.forEach(item => {
        item.text = item.name
        item.value = item.id
      })
      this.setData({
        option1: [{
          text: '全部科室',
          value: 0
        }].concat(res.data.department)
      })
    })
  },
  //获取医生列表
  getDoctorList(deptId, level, name) {
    wx.showLoading({
      title: '加载中'
    })
    let query = {
      sub_department_id: deptId,
      level: level,
      name: name,
      type: '护士',
    }
    if (deptId == 0) {
      delete query.sub_department_id
    }
    if (level == '全部护士' || level == '') {
      delete query.level
    }
    if (name == '') {
      delete query.name
    }
    ApiGetDoctorList(query).then(res => {
      this.setData({
        doctorArr: res.data
      })
      wx.hideLoading()
    })
  },

  //切换科室
  deptSwitch({
    detail
  }) {
    this.setData({
      value1: detail
    })
    this.getDoctorList(detail, this.data.value2, this.data.name)
  },

  huSwitch({
    detail
  }) {
    this.setData({
      value2: detail
    })
    this.getDoctorList(this.data.value1, detail, this.data.name)
  },

  //搜索姓名
  onSearch({
    detail
  }) {
    this.setData({
      name: detail
    })
    this.getDoctorList(this.data.value1, this.data.value2, detail)
  },


  //点击图片
  doctorItem(e) {
    console.log(e)
    wx.navigateTo({
      url: `/pages/doctorDetails/index?id=${e.currentTarget.dataset.v.id}&&consultation_type=${e.currentTarget.dataset.v.consultation_type}&&jiezhen=${e.currentTarget.dataset.v.jiezhen}`,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})